package com.cafe.action.admin;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;

import com.cafe.model.CafeInfo;
import com.cafe.service.CafeInfoService;
import com.malamute.core.action.BaseAction;
import com.malamute.core.action.CrudMethod;

/**
 * 
 * @Project：malamute
 * @Title：CafeAction
 * @Description：
 * @author：chen
 * @date：2012-2-13 上午10:36:20
 * @version
 * 
 */
public class CafeInfoAction extends BaseAction implements CrudMethod {
	private CafeInfo cafeInfo;
	@Autowired(required = false)
	private CafeInfoService cafeInfoService;

	public CafeInfo getCafeInfo() {
		return cafeInfo;
	}

	public void setCafeInfo(CafeInfo cafeInfo) {
		this.cafeInfo = cafeInfo;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @return
	 * 
	 * @throws Exception
	 * 
	 * @see com.malamute.core.action.CrudMethod#save()
	 */
	@Override
	public String save() throws Exception {
		cafeInfoService.saveCafeInfo(cafeInfo);
		return INPUT;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @return
	 * 
	 * @throws Exception
	 * 
	 * @see com.malamute.core.action.CrudMethod#update()
	 */

	public String update() throws Exception {
		
		return INPUT;
	}

	@Override
	public String form() throws Exception {
		cafeInfoService.updateCafeInfo(cafeInfo);
		return FORM;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @return
	 * 
	 * @throws Exception
	 * 
	 * @see com.malamute.core.action.CrudMethod#list()
	 */
	@Override
	public String list() throws Exception {
		DetachedCriteria criteria = DetachedCriteria.forClass(CafeInfo.class);
		List result = cafeInfoService.listAllCafeInfos(criteria);
		if (!result.isEmpty()) {
			this.cafeInfo = (CafeInfo) result.iterator().next();
		}
		return INPUT;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @return
	 * 
	 * @throws Exception
	 * 
	 * @see com.malamute.core.action.CrudMethod#search()
	 */
	@Override
	public String search() throws Exception {
		return null;
	}

}
